<?php

if (!file_exists(TMSVC_PATH_TMP.'/'.TMSVC_NAME2.'.server.php')) {
    function registerServer($dir) {
        $ret = '';
        $dir_handle = opendir($dir);
        while ($dir_content = readdir($dir_handle)) {
            if ($dir_content{0} == '.') continue; // we do not parse hidden files
            if (is_dir($dir.'/'.$dir_content))
                 $ret.= registerServer($dir.'/'.$dir_content);
            else {
                unset($info);
                include $dir.'/'.$dir_content;
                if (isset($info['complexTypes'])) {
                    foreach ($info['complexTypes'] as $t) {
                        if (isset($t['struct']))
                            $ret.='$server->wsdl->addComplexType(\''.$t['name'].'\',\'complexType\',\'struct\',\'all\',\'\', '.var_export($t['struct'], true).');';
                        if (isset($t['array']))
                            $ret.='$server->wsdl->addComplexType(\''.$t['name'].'\',\'complexType\',\'array\',\'\',\'SOAP-ENC:Array\',array(),array(array(\'ref\'=>\'SOAP-ENC:arrayType\',\'wsdl:arrayType\'=>\'tns:'.$t['array'].'[]\')),\'tns:'.$t['array'].'\');';
                    }
                }
                $ret.= '$server->register(
            \''.$info['function'].'\',
            '.var_export($info['in'], true).',
            '.var_export($info['out'], true).',
            TMSVC_NAMESPACE,
            false,
            \'rpc\',
            \'encoded\',
            \''.addslashes($info['documentation']).'\'
        );';
            }
        }
        closedir($dir_handle);
        return $ret;
    }
    // generate class
    $class_code = '<?php ';
    $class_code.= registerServer(TMSVC_PATH_INFO);
    $class_code.= ' ';
    file_put_contents(TMSVC_PATH_TMP.'/'.TMSVC_NAME2.'.server.php', $class_code);
}

